<%
# View which displays a list of all the group_types under an instance,
# specified by @instance.  
#
# Author::      Eli Fox-Epstein, efoxepstein@wesleyan.edu
# Author::      Dimitar Gochev, dimitar.gochev@trincoll.edu
# Copyright::   Humanitarian FOSS Project (http://www.hfoss.org), Copyright (C) 2009.
# License::     http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License (LGPL)
%>

<% content_for :title, title('Groups', @instance.short_name)%>

<% content_for :body do %>
	<%=pretty_button_if GroupType.creatable_by?(@current_user), :new_group_type, new_instance_group_type_url(@instance), 'New Group Type' -%>
	<%= flashes %>
	<div id="wrap">
		<h1>Groups <span class="tiny">&laquo; <%=@instance.long_name%></span></h1>
		<h2>My Groups</h2>
		<ul id="groups-list" class="listy">
		<% @current_user.groups.each do |g| %>
			<li>
				<%= link_to g.name, instance_group_type_group_url(@instance, g.group_type, g) %>
				&ndash; <%= g.users.size %> members.
				<% unless g.chairs.empty? %>
					Chairs: 
					<%= (g.chairs.map{|c|c.full_name}).join(', ') %>
				<% end %>
			</li>
		<% end %>
		</ul>
		<h2 class="second-heading">All Groups</h2>
		<ul id="group-type-list" class="listy outer">
		<% @group_types.each do |gt| %>
			<li class="outer">
				<%= link_to gt.name.pluralize, instance_group_type_url(@instance, gt), :class=>:title %>
				&mdash; <%= gt.groups.size%> groups
				<% if gt.destroyable_by?(@current_user) %> 
				<span class="delete-grouptype">[<%=link_to 'X', instance_group_type_path(@instance, gt), :method => :delete, :confirm => 'Really delete group type?'%>]</span>
				<% end %>
				<ul id="groups-list" class="listy">
				<% gt.groups.each do |g| %>
					<li>
						<%= link_to g.name, instance_group_type_group_url(@instance, g.group_type, g) %>
						&ndash; <%= g.users.size %> members.
						<% unless g.chairs.empty? %>
							Chairs: 
							<%= (g.chairs.map{|c|c.full_name}).join(', ') %>
						<% end %>
						<% unless g.users.include? @current_user %>
						&ndash; <%= link_to 'Join', instance_memberships_path(@instance, :group_id => g.id, :user_id => @current_user), :method => :post -%>
						<% end %>
					</li>
				<% end %>
				</ul>
			</li>
		<% end %>
		</ul>
	</div>
<% end %>
